'use strict'
const SUN = require('../base/sun')
const WebSocket = require('ws')
const nodeMgr = require('./nodeMgr')
let rootSerConfig = SUN.serConfig.rootSerConfig

class RootServer {
    constructor() {
        this.server = null
    }

    //创建WS服务器
    createServer() {
        let self = this
        self.server = new WebSocket.Server({
            host: rootSerConfig.ip,
            port: rootSerConfig.port
        })
        console.info(`网关主服务器启动 ${rootSerConfig.ip}:${rootSerConfig.port}`)
        SUN.emit('rootSerStart')
        this.server.on('connection', function(socket) {
            //创建会话
            console.info('新子节点服务器连接')
            nodeMgr.create(socket)
        })
    }
}
let rootServer = new RootServer()
module.exports = rootServer
